var MonthReport = function() {
	return {
		datatable : null,
		init : function() {
			$("#startTime").datetimepicker({lang:'ch',timepicker:false, format:"Y-m"});
			this.initSearch();
			this.initListener();
		},
		initSearch : function() {
			if (!jQuery().dataTable) {
				return;
			}
			var monthReportListTable = $("#monthReportListTable").dataTable({
				"paging" : false,
				"sAjaxSource" : ctx + "/monthReport/search?now=" + new Date().getTime(),
				/* 使用post方式 */
				"fnServerData" : function(sSource, aoData, fnCallback) {
					var postData = {page : 1,start : 0,rows : 0,params : {}};
					if($('#userIds').val()){
						postData.params.userIds = $('#userIds').val();
						console.log($('#userIds').val());					
					}
					
					if($('#startTime').val()){
						postData.params.startTime = $('#startTime').val();
					}else{
						postData.params.startTime = "";
					}
					
					// 参数
					for (var i = 0, size = aoData.length; i < size; i++) {
						if (aoData[i].name == 'iDisplayLength') {
							postData.rows = aoData[i].value;
						} else if (aoData[i].name == 'iDisplayStart') {
							postData.start = aoData[i].value;
						} else if (aoData[i].name == 'sEcho') {
							postData.page = aoData[i].value;
						}
					}
					$.ajax({
						"dataType" : 'json',
						"cache": false,
						"type" : "POST",
						"url" : sSource,
						"data" : postData,
						"success" : function(data, textStatus, jqXHR){
							fnCallback(data.data, textStatus, jqXHR);
						}
					});
				},
				"bAutoWidth":false,
				"aoColumnDefs" : [
				{
					"data" : "index",
					"aTargets" : [ 0 ]
				},{
					"data" : "emplName",
					"aTargets" : [ 1 ],
				},{
					"aTargets" : [ 2 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_1);
					}
				},{
					"aTargets" : [ 3 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_2);
					}
				},{
					"aTargets" : [ 4 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_3);
					}
				},{
					"aTargets" : [ 5 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_4);
					}
				},{
					"aTargets" : [ 6 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_5);
					}
				},{
					"aTargets" : [ 7 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_6);
					}
				},{
					"aTargets" : [ 8 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_7);
					}
				},{
					"aTargets" : [ 9 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_8);
					}
				},{
					"aTargets" : [ 10 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_9);
					}
				},{
					"aTargets" : [ 11 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_10);
					}
				},{
					"aTargets" : [ 12 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_11);
					}
				},{
					"aTargets" : [ 13 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_12);
					}
				},{
					"aTargets" : [ 14 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_13);
					}
				},{
					"aTargets" : [ 15 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_14);
					}
				},{
					"aTargets" : [ 16 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_15);
					}
				},{
					"aTargets" : [ 17 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_16);
					}
				},{
					"aTargets" : [ 18 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_17);
					}
				},{
					"aTargets" : [ 19 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_18);
					}
				},{
					"aTargets" : [ 20 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_19);
					}
				},{
					"aTargets" : [ 21 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_20);
					}
				},{
					"aTargets" : [ 22 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_21);
					}
				},{
					"aTargets" : [ 23 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_22);
					}
				},{
					"aTargets" : [ 24 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_23);
					}
				},{
					"aTargets" : [ 25 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_24);
					}
				},{
					"aTargets" : [ 26 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_25);
					}
				},{
					"aTargets" : [ 27 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_26);
					}
				},{
					"aTargets" : [ 28 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_27);
					}
				},{
					"aTargets" : [ 29 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_28);
					}
				},{
					"aTargets" : [ 30 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_29);
					}
				},{
					"aTargets" : [ 31 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_30);
					}
				},{
					"aTargets" : [ 32 ],
					"mRender" : function(data, type, full) {
						return MonthReport.checkValue(full.day_31);
					}
				},{
					"data" : "vacation_nuptialOrFuneral",
					"aTargets" : [ 33 ]
				},{
					"data" : "vacation_sick",
					"aTargets" : [ 34 ]
				},{
					"data" : "vacation_affair",
					"aTargets" : [ 35 ]
				},{
					"data" : "vacation_year",
					"aTargets" : [ 36 ]
				},{
					"data" : "absenteeism",
					"aTargets" : [ 37 ]
				},{
					"data" : "workInjury",
					"aTargets" : [ 38 ]
				},{
					"data" : "extraWork",
					"aTargets" : [ 39 ]
				},{
					"data" : "daysOff",
					"aTargets" : [ 40 ]
				},{
					"data" : "attendanceHours",
					"aTargets" : [ 41 ]
				},{
					"data" : "attendanceDays",
					"aTargets" : [ 42 ]
				},{
					"aTargets" : [ 43 ],
					"mRender" : function(data, type, full) {
						return "";
					}
				}]
			});
			this.datatable = monthReportListTable;
		},reSearch:function(){
        	this.datatable.fnDraw();
        },removeClass:function(){//去除Form表单的验证样式
        	$('.form-group','#editForm').removeClass('has-success').removeClass('has-error');
    		 $('span').remove('.help-block');
        },checkValue:function(num){
        	if(num){
        		if(num >= 8){
        			return "/"
        		}else if(num<8 && num>0){
        			return "▼";
        		}else{
        			return "×";
        		}
        	}else{
        		return "#";
        	}
        	
        },initListener:function(){
			/**
			 * 监听开关事件
			 */
        	/*
        	 * 选择员工modal
        	 */
        	jQuery("#selected").click(function(){
        		$("#groupUserModal").modal('show');
        	});
        	/*
        	 * 查询
        	 */
        	jQuery("#searchBtn").click(function() { 
        		MonthReport.reSearch();
				return false;
			});
     	}
	}
}();